//
//  DCEmptyTableViewCell.m
//  Driver
//
//  Created by 大橙子 on 2018/11/8.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCEmptyTableViewCell.h"

static const int kBaseCellHeight = 30;
@interface DCEmptyTableViewCell ()
@property (nonatomic,strong) UILabel *totalNumLabel;
@property (nonatomic,strong) UIButton *transportBtn;
@end
@implementation DCEmptyTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCEmptyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCEmptyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = BackgroundColor;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    [self setUpBaseUIView];
    self.totalNumLabel = [[UILabel alloc]init];
    self.totalNumLabel.textAlignment = NSTextAlignmentRight;
    self.totalNumLabel.font = FONT(23);
//    self.totalNumLabel.textColor = [UIColor redColor];
//    self.totalNumLabel.backgroundColor = [UIColor cyanColor];
    [self.secondView addSubview:self.totalNumLabel];
    
    self.transportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.transportBtn.backgroundColor = BlueColor;
    [self.transportBtn setTitle:@"上报运力" forState:UIControlStateNormal];
    self.transportBtn.layer.cornerRadius = 14;
    self.transportBtn.clipsToBounds = YES;
    [self.transportBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    self.transportBtn.layer.borderWidth = 1;
    self.transportBtn.layer.borderColor = BlueColor.CGColor;
    self.transportBtn.titleLabel.font = FONT(16);
    self.transportBtn.tag = 2;
    [self.thirdView addSubview:self.transportBtn];
    
    [self.protectBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.driveMsgBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.transportBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setUpLayoutSubViews];
    __weak typeof(self) weakself = self;
    self.secondView.frame = CGRectMake(0, self.firstView.bottom+1, self.width, kBaseCellHeight*3);
//    self.carImageView.frame = CGRectMake(10, 15, self.secondView.height- 30, self.secondView.height - 30);
    self.carImageView.size = CGSizeMake(kBaseCellHeight*3-25, kBaseCellHeight*3-25);
    self.carImageView.y = (self.secondView.height - self.carImageView.height)/2;
    self.carImageView.x = 10;
    self.nameLabel.frame = CGRectMake(self.carImageView.right+5, 0, 100*WIDTHSCALE6, kBaseCellHeight);
    self.phoneLabel.frame = CGRectMake(self.nameLabel.x, self.nameLabel.bottom, 150*WIDTHSCALE6, kBaseCellHeight);
    self.locationLabel.frame = CGRectMake(self.nameLabel.x, self.phoneLabel.bottom, self.secondView.width - self.carImageView.width -15, kBaseCellHeight);

    [self.totalNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.secondView.mas_top).offset(0);
        make.right.equalTo(weakself.secondView.mas_right).offset(-10);
        make.left.equalTo(weakself.phoneLabel.mas_right);
        make.height.mas_offset(kBaseCellHeight + 20);
    }];
    
    self.thirdView.frame = CGRectMake(0, self.secondView.bottom+1, self.width, kBaseSubViewHeight);
    [self.transportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.thirdView.mas_right).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    
    [self.driveMsgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.transportBtn.mas_left).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    
    [self.protectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.driveMsgBtn.mas_left).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    
}
-(void)setMyModel:(DCCarManagerModel *)myModel
{
    _myModel = myModel;
    self.plateNumLabel.text = myModel.plateNum;
    self.stateLabel.text = myModel.state;
    self.nameLabel.textLabel.text = myModel.name;
    self.phoneLabel.textLabel.text = myModel.tel;
    self.locationLabel.textLabel.text = myModel.location;
    NSString *text = [NSString stringWithFormat:@"%@/%@",myModel.finishedNum,myModel.totalNum];
    self.totalNumLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:text subStringColor:[UIColor redColor] subString:myModel.finishedNum andFont:FONT(25)];
}

-(void)btnDidClick:(UIButton *)button
{
    if (button.tag == 0) {
        DCLog(@"2-保养维护");
    }else if (button.tag == 1){
        DCLog(@"2-驾驶数据");
    }else if (button.tag == 2){
        DCLog(@"2-上报运力");
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
